import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

import Login from '@/views/login'
import Home from '@/views/index'

import AddGoods from '@/views/goods/addGoods'
import GoodsList from '@/views/goods/goodsList'
import GoodsClassify from '@/views/goods/goodsClassify'
import ClassifyList from '@/views/goods/classifyList'

import AddSwipeImg from '@/views/mini/addSwipeImg'
import SwipeImgList from '@/views/mini/swipeImgList'

const router = new VueRouter({
    routes: [
      // 动态路径参数 以冒号开头
      { 
        path: '/login', 
        component: Login, 
        name: 'login'
        // meta: {
        //   isPublic: true
        // }
      },
      { 
        path: '/', 
        component: Home, 
        name: 'home',
        children: [
          {
            path: '/goodsClassify',
            component: GoodsClassify,
            name: 'goodsClassify'
          },
          {
            path: '/goodsClassify/:id',
            component: GoodsClassify,
            name: 'goodsClassify'
          },
          {
            path: '/classifyList',
            component: ClassifyList,
            name: 'classifyList'
          },
          {
            path: '/addGoods',
            component: AddGoods,
            name: 'addGoods'
          },
          {
            path: '/addGoods/:id',
            component: AddGoods,
            name: 'addGoods'
          },
          {
            path: '/goodsList',
            component: GoodsList,
            name: 'goodsList'
          },
          {
            path: '/addSwipeImg',
            component: AddSwipeImg,
            name: 'addSwipeImg'
          },
          {
            path: `/addSwipeImg/:id`,
            component: AddSwipeImg,
            name: 'addSwipeImg'
          },
          {
            path: '/swipeImgList',
            component: SwipeImgList,
            name: 'swipeImgList'
          }
        ]
      }
    ]
  })
  // router.beforeEach((to, from, next) => {
  //   const token = window.localStorage.getItem('shoppingToken')
  //   if (!token && !to.meta.isPublic) {
  //     Vue.prototype.$message({
  //       type: 'error',
  //       message: '请先登录'
  //     })
  //     router.push('/login')
  //   }
  //   next()
  // })
export default router